﻿var emailCheckerTimer;

var _Available = document.getElementById("ctl00_ctl00_ContentPlaceHolder3_ContentPlaceHolder1_Available");
var _Unavailable = document.getElementById("ctl00_ctl00_ContentPlaceHolder3_ContentPlaceHolder1_Unavailable");
var _Checking = document.getElementById("ctl00_ctl00_ContentPlaceHolder3_ContentPlaceHolder1_Checking");



function emailChecker(email) {
    var _EmaildivStatus = document.getElementById("ctl00_ctl00_ContentPlaceHolder3_ContentPlaceHolder1_FormView1_EmaildivStatus");
    clearTimeout(emailCheckerTimer);
    if (email.length == 0)
        _EmaildivStatus.innerHTML = "";
    else {
        _EmaildivStatus.innerHTML = "<span style='color: #ccc;'>" + _Checking.value + "</span>";
        emailCheckerTimer = setTimeout("checkEmailUsage('" + email + "');", 750);
        }
    }

    function checkEmailUsage(email) {
        var UserContent = email;
        var _Currentemail = "ctl00_ctl00_ContentPlaceHolder3_ContentPlaceHolder1_Currentemail";
        var _CurrentemailValue = document.getElementById(_Currentemail).value;
        //alert("email is: " + email + "_CurrentemailValue: " + _CurrentemailValue);
        if (email != _CurrentemailValue) {
            //alert("email is: " + email + "_CurrentemailValue: " + _CurrentemailValue);
            Nivdal.WebServices.CheckEmail(email, OnEmailSucceeded, onFailure);
        }
        else {
            var _EmaildivStatus = document.getElementById("ctl00_ctl00_ContentPlaceHolder3_ContentPlaceHolder1_FormView1_EmaildivStatus");
            var _UpdateButton = document.getElementById("ctl00_ctl00_ContentPlaceHolder3_ContentPlaceHolder1_FormView1_UpdateButton");
            //_EmaildivStatus.innerHTML = "<span style='color: DarkGreen;'>" + _Available.value + "</span>";
            _EmaildivStatus.innerHTML = "";
            _UpdateButton.disabled = false;
        }
                
        //alert("UserName is:" + username);
    }

    function onFailure(theError) {
        //console.log(theError);
        alert("Error is: " + theError);
    }

    // Callback function invoked on successful completion of the page method.
    function OnEmailSucceeded(result) {
        var _EmaildivStatus = document.getElementById("ctl00_ctl00_ContentPlaceHolder3_ContentPlaceHolder1_FormView1_EmaildivStatus");
        var _UpdateButton = document.getElementById("ctl00_ctl00_ContentPlaceHolder3_ContentPlaceHolder1_FormView1_UpdateButton");


        if (result == true) {
            isMailAvail = true;
            _EmaildivStatus.innerHTML = "<span style='color: DarkGreen;'>" + _Available.value + "</span>";
            _UpdateButton.disabled = false;
        }

        if (result == false) {
            _EmaildivStatus.innerHTML = "<span style='color: Red;'>" + _Unavailable.value + "</span>";
            _UpdateButton.disabled = true;
        }
    }

    function showHideControl() {
        var PayType = this.document.getElementById("<%= PayTypeRadioButtonList.ClientID %>");
        alert(PayType);
//        var Control = document.getElementById(ControlId);
//        if (ShowHide == "Show") {
//            Control.style.display = "block"; //to show it
//        }
//        if (ShowHide == "Hide") {
//            Control.style.display = "none"; //to hide it
//        }
    }
       
 